package com.gxgeek.redis.application.lock;

import com.gxgeek.redis.application.redistool.JedisExecutor;
import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;

/**
 * Created by gx on 2017/7/7.
 */
@Slf4j //setnx
public class RedisKill_2 {

    public static void main(String[] args) {
        int i = 100;
        while (i>0){
            new lock().start();
            i--;
        }
    }
}
@Slf4j

class lock extends Thread{

    @Override
    public void run() {
        // TODO Auto-generated method stub
        System.out.println(Thread.currentThread().getName());
        try {
            if(JedisExecutor.execute(jedis->jedis.setnx("look", "1") == 1)){
                System.out.println(Thread.currentThread().getName()+"success");
                JedisExecutor.execute(jedis->jedis.set("food", Thread.currentThread().getName()));
            }else{
                System.out.println(Thread.currentThread().getName() + "未访问");
            }
        } catch (Exception e) {
            // TODO: handle exception
           log.error(e.getMessage(),e);
        }
    }

}
